<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>NinjaBot - Advanced Trading Analytics</title>
    <script src="https://cdn.plot.ly/plotly-2.27.0.min.js"></script>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        :root {
            --bg-primary: #0a0e27;
            --bg-secondary: #151932;
            --bg-card: #1a1f3a;
            --border-color: #2a2f4a;
            --text-primary: #e4e7eb;
            --text-secondary: #9ca3af;
            --accent-green: #10b981;
            --accent-red: #ef4444;
            --accent-blue: #3b82f6;
            --accent-purple: #8b5cf6;
            --accent-yellow: #f59e0b;
            --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
        }

        body {
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
            background: var(--bg-primary);
            color: var(--text-primary);
            overflow-x: hidden;
        }

        /* Header */
        .header {
            background: var(--bg-secondary);
            border-bottom: 1px solid var(--border-color);
            padding: 1rem 2rem;
            position: sticky;
            top: 0;
            z-index: 100;
            backdrop-filter: blur(10px);
        }

        .header-content {
            max-width: 1800px;
            margin: 0 auto;
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 2rem;
        }

        .logo {
            font-size: 1.5rem;
            font-weight: 700;
            background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
            background-clip: text;
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .logo::before {
            content: "🥷";
            font-size: 1.8rem;
        }

        .pair-selector {
            display: flex;
            gap: 0.5rem;
            flex-wrap: wrap;
            flex: 1;
            justify-content: center;
        }

        .pair-btn {
            padding: 0.5rem 1.25rem;
            background: var(--bg-card);
            border: 1px solid var(--border-color);
            border-radius: 8px;
            color: var(--text-secondary);
            text-decoration: none;
            font-weight: 500;
            font-size: 0.875rem;
            transition: all 0.2s;
            cursor: pointer;
        }

        .pair-btn:hover {
            background: var(--bg-primary);
            border-color: var(--accent-blue);
            color: var(--text-primary);
            transform: translateY(-1px);
        }

        .pair-btn.active {
            background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
            border-color: transparent;
            color: white;
            box-shadow: var(--shadow);
        }

        .history-btn {
            padding: 0.5rem 1.25rem;
            background: var(--accent-green);
            border: none;
            border-radius: 8px;
            color: white;
            font-weight: 600;
            font-size: 0.875rem;
            cursor: pointer;
            transition: all 0.2s;
            text-decoration: none;
            display: inline-block;
        }

        .history-btn:hover {
            background: #059669;
            transform: translateY(-1px);
            box-shadow: var(--shadow);
        }

        /* Main Container */
        .container {
            max-width: 1800px;
            margin: 0 auto;
            padding: 1.5rem;
        }

        /* Stats Grid */
        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 1rem;
            margin-bottom: 1.5rem;
        }

        .stat-card {
            background: var(--bg-card);
            border: 1px solid var(--border-color);
            border-radius: 12px;
            padding: 1.25rem;
            transition: all 0.2s;
        }

        .stat-card:hover {
            border-color: var(--accent-blue);
            transform: translateY(-2px);
            box-shadow: var(--shadow);
        }

        .stat-label {
            font-size: 0.75rem;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            color: var(--text-secondary);
            margin-bottom: 0.5rem;
            font-weight: 600;
        }

        .stat-value {
            font-size: 1.75rem;
            font-weight: 700;
            line-height: 1.2;
        }

        .stat-change {
            font-size: 0.875rem;
            margin-top: 0.25rem;
            display: flex;
            align-items: center;
            gap: 0.25rem;
        }

        .positive {
            color: var(--accent-green);
        }

        .negative {
            color: var(--accent-red);
        }

        .neutral {
            color: var(--text-secondary);
        }

        /* Chart Container */
        .chart-container {
            background: var(--bg-card);
            border: 1px solid var(--border-color);
            border-radius: 12px;
            padding: 1.5rem;
            margin-bottom: 1.5rem;
            box-shadow: var(--shadow);
        }

        .chart-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 1rem;
        }

        .chart-title {
            font-size: 1.25rem;
            font-weight: 600;
        }

        .chart-controls {
            display: flex;
            gap: 0.5rem;
        }

        .control-btn {
            padding: 0.5rem 1rem;
            background: var(--bg-secondary);
            border: 1px solid var(--border-color);
            border-radius: 6px;
            color: var(--text-secondary);
            font-size: 0.75rem;
            cursor: pointer;
            transition: all 0.2s;
            font-weight: 500;
        }

        .control-btn:hover {
            background: var(--bg-primary);
            color: var(--text-primary);
        }

        .control-btn.active {
            background: var(--accent-blue);
            border-color: var(--accent-blue);
            color: white;
        }

        #main-chart, #equity-chart, #performance-chart {
            width: 100%;
            height: 600px;
        }

        #equity-chart {
            height: 300px;
        }

        #performance-chart {
            height: 400px;
        }

        /* Trade Table */
        .trade-table-container {
            background: var(--bg-card);
            border: 1px solid var(--border-color);
            border-radius: 12px;
            padding: 1.5rem;
            margin-bottom: 1.5rem;
            overflow-x: auto;
        }

        .trade-table {
            width: 100%;
            border-collapse: collapse;
        }

        .trade-table thead {
            background: var(--bg-secondary);
        }

        .trade-table th {
            padding: 0.75rem 1rem;
            text-align: left;
            font-size: 0.75rem;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            color: var(--text-secondary);
            font-weight: 600;
            border-bottom: 1px solid var(--border-color);
        }

        .trade-table td {
            padding: 0.75rem 1rem;
            border-bottom: 1px solid var(--border-color);
            font-size: 0.875rem;
        }

        .trade-table tbody tr:hover {
            background: var(--bg-secondary);
        }

        .badge {
            display: inline-block;
            padding: 0.25rem 0.75rem;
            border-radius: 12px;
            font-size: 0.75rem;
            font-weight: 600;
        }

        .badge-buy {
            background: rgba(16, 185, 129, 0.2);
            color: var(--accent-green);
        }

        .badge-sell {
            background: rgba(239, 68, 68, 0.2);
            color: var(--accent-red);
        }

        .badge-profit {
            background: rgba(16, 185, 129, 0.2);
            color: var(--accent-green);
        }

        .badge-loss {
            background: rgba(239, 68, 68, 0.2);
            color: var(--accent-red);
        }

        /* Loading */
        .loading {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 400px;
            font-size: 1.25rem;
            color: var(--text-secondary);
        }

        .spinner {
            width: 40px;
            height: 40px;
            border: 4px solid var(--border-color);
            border-top-color: var(--accent-blue);
            border-radius: 50%;
            animation: spin 1s linear infinite;
            margin-right: 1rem;
        }

        @keyframes spin {
            to { transform: rotate(360deg); }
        }

        /* Responsive */
        @media (max-width: 768px) {
            .header-content {
                flex-direction: column;
                gap: 1rem;
            }

            .pair-selector {
                justify-content: flex-start;
            }

            .stats-grid {
                grid-template-columns: repeat(2, 1fr);
            }

            #main-chart, #equity-chart, #performance-chart {
                height: 400px;
            }
        }

        /* Tooltips */
        .tooltip {
            position: relative;
            display: inline-block;
        }

        .tooltip .tooltiptext {
            visibility: hidden;
            background-color: var(--bg-secondary);
            color: var(--text-primary);
            text-align: center;
            border-radius: 6px;
            padding: 0.5rem;
            position: absolute;
            z-index: 1;
            bottom: 125%;
            left: 50%;
            margin-left: -60px;
            opacity: 0;
            transition: opacity 0.3s;
            font-size: 0.75rem;
            border: 1px solid var(--border-color);
        }

        .tooltip:hover .tooltiptext {
            visibility: visible;
            opacity: 1;
        }
    </style>
</head>
<body>
    <header class="header">
        <div class="header-content">
            <div class="logo">NinjaBot Analytics</div>
            <nav class="pair-selector" id="pair-selector">
                {{range $val := .pairs}}
                <a class="pair-btn {{if eq $.pair $val}}active{{end}}" href="/enhanced?pair={{ $val }}">{{ $val }}</a>
                {{end}}
            </nav>
            <div style="display: flex; gap: 0.5rem;">
                <a class="history-btn" href="/history?pair={{ $.pair }}">📊 History</a>
                <a class="history-btn" href="/?pair={{ $.pair }}" style="background: var(--bg-card); color: var(--text-secondary);">Classic View</a>
            </div>
        </div>
    </header>

    <div class="container">
        <div id="loading" class="loading">
            <div class="spinner"></div>
            <span>Loading trading data...</span>
        </div>

        <div id="content" style="display: none;">
            <!-- Stats Grid -->
            <div class="stats-grid" id="stats-grid"></div>

            <!-- Main Price Chart -->
            <div class="chart-container">
                <div class="chart-header">
                    <h2 class="chart-title">Price Action & Orders</h2>
                    <div class="chart-controls">
                        <button class="control-btn active" onclick="toggleIndicators()">Indicators</button>
                        <button class="control-btn" onclick="toggleVolume()">Volume</button>
                        <button class="control-btn" onclick="resetZoom()">Reset Zoom</button>
                    </div>
                </div>
                <div id="main-chart"></div>
            </div>

            <!-- Equity Chart -->
            <div class="chart-container">
                <div class="chart-header">
                    <h2 class="chart-title">Portfolio Equity & Position</h2>
                </div>
                <div id="equity-chart"></div>
            </div>

            <!-- Performance Metrics -->
            <div class="chart-container">
                <div class="chart-header">
                    <h2 class="chart-title">Performance Analysis</h2>
                </div>
                <div id="performance-chart"></div>
            </div>

            <!-- Trade History Table -->
            <div class="trade-table-container">
                <h2 class="chart-title" style="margin-bottom: 1rem;">Recent Trades</h2>
                <table class="trade-table" id="trade-table">
                    <thead>
                        <tr>
                            <th>Time</th>
                            <th>Side</th>
                            <th>Type</th>
                            <th>Price</th>
                            <th>Quantity</th>
                            <th>Value</th>
                            <th>Profit</th>
                        </tr>
                    </thead>
                    <tbody id="trade-table-body"></tbody>
                </table>
            </div>
        </div>
    </div>

    <script defer src="/assets/chart_enhanced.js"></script>
</body>
</html>
